package com.example.server.controller;

import com.example.server.entity.Comment;
import com.example.server.redis.RedisService;
import com.example.server.service.CommentService;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController extends BaseController{
    private final CommentService commentService;
    private final RedisService redisService;

    public CommentController(CommentService commentService, RedisService redisService) {
        this.commentService = commentService;
        this.redisService = redisService;
    }

    @PostMapping("create")
    private int create(@RequestBody Comment comment){
        int uid = Integer.parseInt(redisService.getSetString("uid"));
        comment.setUid(uid);
        System.out.println(comment);
        return commentService.create(comment);
    }

    @GetMapping("queryByPid")
    private List<Comment> queryByPid(){
        int pid = Integer.parseInt(redisService.getSetString("productId"));
        Comment comment = new Comment();
        comment.setPid(pid);
        return commentService.queryList("queryByPid",comment);
    }
}
